package com.study.mike.service.impl;

import com.study.mike.common.enums.BizCodeEnum;
import com.study.mike.common.exception.BizException;
import com.study.mike.service.RetryService;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;


/**
 * @author kh
 */
@Service
public class RetryServiceImpl implements RetryService {

    @Override
    @Retryable(value = Exception.class, maxAttempts = 3, backoff = @Backoff(delay = 1000, multiplier = 10, maxDelay = 10000))
    public void retryTransferAccounts(int message) {

        if (message == 1) {
            System.out.println("执行啦");
            throw new BizException(BizCodeEnum.FIND_NO_ONE.getCode(), BizCodeEnum.FIND_NO_ONE.getMsg());
        }

    }

    @Recover
    public void recover(Exception e) {
        System.out.println("回调方法执行！！！ + 结束" + e.getMessage());
        System.out.println(e.getMessage());
    }
}